package kr.hyunist.androidcomplete01saeildamil.ch12;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.*;

public class SpinnerEx1 extends Activity {
	String[] fruits = { "사과", "바나나", "귤", "복숭아", "배", "수박" };
	boolean mInit = false;	
	//스피너는 처음 설정된 0번째 position값을 무조건 반환하므로 boolean변수를 둬서 처리를 무조건 해줘야 함.
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.spinnerex);

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_dropdown_item, fruits);
		
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		
		Spinner spinner = (Spinner) findViewById(R.id.spinnerexspinner);
		
		spinner.setAdapter(adapter);
		
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				if(mInit == false){
					mInit = true;
					return;
				}
				String str = fruits[position] + "맛있다.";
				Toast.makeText(SpinnerEx1.this, str, Toast.LENGTH_SHORT).show();
				
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				
			}
			
		});
	}
}
